package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.FeedBackPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/24 15:00
 * 功能描述： 意见反馈
 * 联系方式：1037438704@qq.com
 */

public class FeedBackActivity extends BaseActivity {
    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.frame_focused)
    FrameLayout frame_focused;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_submission)
    TextView textSubmission;
    @BindView(R.id.edit_context)
    EditText editContext;
    @BindView(R.id.edit_phone)
    EditText editPhone;
    private FeedBackPresenter feedBackPresenter;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_feed_back;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        String count = getIntent().getExtras().getString("count");
        if (count.equals("1")) {
            textCenter.setText("电台举报");
        } else {
            textCenter.setText("意见反馈");
        }

        imageleftFinish.setVisibility(View.VISIBLE);
        feedBackPresenter = new FeedBackPresenter();
        editContext.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (editContext != null) {
                    editContext.requestFocus();
                    InputMethodManager manager = ((InputMethodManager) me.getSystemService(Context.INPUT_METHOD_SERVICE));
                    if (manager != null) {
                        manager.showSoftInput(editContext, 0);
                    }
                }
            }
        }, 1000);
    }

    @OnClick({R.id.image_left_finish, R.id.text_submission, R.id.frame_focused})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_submission:
                feedBackPresenter.getAddFeedBack(token,
                        editContext.getText().toString().trim(),
                        editPhone.getText().toString().trim(),
                        this);
                break;
            case R.id.frame_focused:
                editContext.setFocusableInTouchMode(true);
                editContext.setFocusable(true);
                editContext.requestFocus();
                InputMethodManager manager = ((InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE));
                if (manager != null) {
                    manager.showSoftInput(view, 0);
                }
                break;
            default:
        }
    }

    public static void start(Context me, Class up, String count) {
        Intent intent = new Intent(me, up);
        Bundle bundle = new Bundle();
        bundle.putString("count", count);
        intent.putExtras(bundle);
        me.startActivity(intent);
    }
}
